#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Media;
using ShootThemUp.Sources.AudioElements;
using System;

#endregion

namespace ShootThemUp.Sources.Screens
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MainMenuScreen : MenuScreen
    {
        #region Initialization

        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen(string menuTitle)
            : base("\n\n\n" + menuTitle)
        {
            // Create our menu entries.
            MenuEntry span = new MenuEntry("", false);
            MenuEntry campaignMenuEntry = new MenuEntry("Story Mode", true);
            MenuEntry endlessMenuEntry = new MenuEntry("Endless Mode");
            MenuEntry upgradesMenuEntry = new MenuEntry("Upgrades",true);
            MenuEntry highScoreMenuEntry = new MenuEntry("HighScores",true);
            MenuEntry optionsMenuEntry = new MenuEntry("Options");            

            // Hook up menu event handlers.
            endlessMenuEntry.Selected += PlayGameMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
 

            // Add entries to the menu.
            MenuEntries.Add(span);
            MenuEntries.Add(campaignMenuEntry);
            MenuEntries.Add(endlessMenuEntry);
            MenuEntries.Add(upgradesMenuEntry);
            MenuEntries.Add(highScoreMenuEntry);
            MenuEntries.Add(optionsMenuEntry);

            base.LoadContent();
            Audio audio = Audio.GetInstance;
            MediaPlayer.Stop();
            MediaPlayer.Volume = Audio.SONG_VOLUME;
            MediaPlayer.Play(audio.Menu);
        }


        #endregion

        #region Handle Input


        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>
        private void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            Audio audio = Audio.GetInstance;
            audio.Menu_Click.Play();
            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                               new GameplayScreen());
        }


        /// <summary>
        /// Event handler for when the Options menu entry is selected.
        /// </summary>
        private void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            Audio audio = Audio.GetInstance;
            audio.Menu_Click.Play();
            ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }


        /// <summary>
        /// When the user cancels the main menu, we exit the game.
        /// </summary>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            ScreenManager.Game.Exit();
        }


        #endregion
    }
}
